<template>
	<view class="userpassword">
		<input type="text" v-model="password_1" placeholder-style="font-size:14px" placeholder="请输入原密码" />
		<input type="text" v-model="password_2" placeholder-style="font-size:14px" placeholder="请输入新密码" />
		<input type="text" v-model="password_3" placeholder-style="font-size:14px" placeholder="再次输入新密码" />
		<view class="btn" @click="changePassword()">
			立即修改
		</view>
	</view>
</template>

<script>
	import { changePassword } from '../../api/user.js'
	export default {
		data() {
			return {
				password_1: '',
				password_2: '',
				password_3: ''
			}
		},
		onLoad() {
			
		},
		methods: {
			changePassword(){
				if(this.password_2 != this.password_3){
					uni.showToast({
						title:'两次密码不正确，请重新输入',
						icon:'none'
					})
					return false
				}
				changePassword({
					old_password:this.password_1,
					new_password:this.password_2
				}).then(res=>{
					uni.showToast({
						title:res.message,
						icon:'none'
					})
					setTimeout(()=>{
						if(res.status == 1){
							uni.redirectTo({
								url:'/pages/usersetup/index'
							})
						}
					},1000)
				})
			}
		}
	}
</script>

<style lang="scss">
	.userpassword {
		padding-top: 20rpx;

		input {
			background: #FFFFFF;
			width: 80%;
			padding: 5%;
			margin: 10px auto;
			border-radius: 16rpx;
		}
	}
</style>
